package routers

import (
	"go-ddd-ecommerce/internal/interfaces/handlers"

	"github.com/gin-gonic/gin"
)

type Router struct {
	userController    *handlers.UserController
	productController *handlers.ProductController
	orderController   *handlers.OrderController
}

func NewRouter(
	userController *handlers.UserController,
	productController *handlers.ProductController,
	orderController *handlers.OrderController,
) *Router {
	return &Router{
		userController:    userController,
		productController: productController,
		orderController:   orderController,
	}
}

func (r *Router) SetupRoutes() *gin.Engine {
	router := gin.Default()

	// 用户路由组
	userGroup := router.Group("/users")
	{
		userGroup.POST("/", r.userController.CreateUser)
		userGroup.POST("/get", r.userController.GetUser)
		userGroup.POST("/update_password", r.userController.UpdatePassword)
		userGroup.POST("/add_balance", r.userController.AddBalance)
	}

	// 商品路由组
	productGroup := router.Group("/products")
	{
		productGroup.POST("/", r.productController.CreateProduct)
		productGroup.GET("/", r.productController.GetProducts)
		productGroup.POST("/get_product", r.productController.GetProduct)
	}

	// 订单路由组
	orderGroup := router.Group("/orders")
	{
		orderGroup.POST("/purchase", r.orderController.Purchase)
		orderGroup.POST("/user_orders", r.orderController.GetUserOrders)
	}

	return router
}
